﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace XYZshell.Game.CardGameEngine
{
	/// <summary>
	/// 直接返回值的表达式
	/// </summary>
	[Expression("direct")]
	public  class DirectValueExpression:BaseExpression
	{
		/// <summary>
		/// 直接表达式的值
		/// </summary>
		public bool Value
		{
			get;
			set;
		}

		public DirectValueExpression()
		{
		}

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="value"></param>
		public DirectValueExpression( bool value )
		{
			Value = value;

		}
		/// <summary>
		/// 直接表达式的值
		/// </summary>
		/// <returns></returns>
		public override bool Result()
		{
			return Value;
		}

		/// <summary>
		/// 从XML生产直接表达式
		/// </summary>
		/// <param name="xmlnode"></param>
		/// <returns></returns>
		public static new DirectValueExpression FromXML( string xmlnode )
		{
			XObject xo=new XObject( xmlnode );
			DirectValueExpression rtn=new DirectValueExpression();
			bool value=false;
			Boolean.TryParse( xo.Value,out value );
			rtn.Value = value;
			return rtn;
		}

		/// <summary>
		/// 转换为XML
		/// </summary>
		/// <returns></returns>
		public override string ToXML()
		{
			StringBuilder sb=new StringBuilder();
			sb.AppendFormat( "<expression type=\"{0}\" value=\"{1}\">\r\n", this.GetAttribute().ID,this.Value );
			sb.Append( GetParamsXml() );
			sb.AppendFormat( "</expression><!-- expresion({0}) -->\r\n", GetAttribute().ID );

			return sb.ToString();
		}
	}
}
